package com.heima.comment.controller.v1;

import com.heima.comment.dtos.*;
import com.heima.comment.service.CommentRepayService;
import com.heima.comment.service.CommentService;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 发表评论的方法
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto){
        return commentService.saveComment(dto);
    }

    /**
     * 点赞评论
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto dto) {
        return commentService.like(dto);
    }

    /**
     * 加载评论列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult findByArticleId(@RequestBody CommentListDto dto){
        return commentService.findByArticleId(dto);
    }





    /**
     * 评论回复
     */
    @RestController
    @RequestMapping("/api/v1/comment_repay")
    public class CommentRepayController {

        @Autowired
        private CommentRepayService commentRepayService;

        /**
         * 查询评论回复列表
         * @param dto
         * @return
         */
        @PostMapping("/load")
        public ResponseResult loadCommentRepay(@RequestBody CommentRepayListDto dto) {
            return commentRepayService.load(dto);
        }

        /**
         * 发送评论回复
         * @param dto
         * @return
         */
        @PostMapping("/save")
        public ResponseResult saveCommentRepay(@RequestBody CommentRepayDto dto) {
            return commentRepayService.saveCommentRepay(dto);
        }

        /**
         * 点赞评论回复
         * @param dto
         * @return
         */
        @PostMapping("/like")
        public ResponseResult saveCommentRepayLike(@RequestBody CommentRepayLikeDto dto) {
            return commentRepayService.like(dto);
        }

    }
}
